package com.example.g2daylx2.user

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.g2daylx2.R
import com.example.g2daylx2.bvm.LongViewModel
import com.example.g2daylx2.databinding.ActivityLoginBinding
import com.example.lib_base.net.mvvm.BaseActivity
import dagger.hilt.android.AndroidEntryPoint
@Route(path = "/app/LoginActivity")
@AndroidEntryPoint
class LoginActivity : BaseActivity<ActivityLoginBinding,LongViewModel>() {
    override fun initView() {
        binding.login.setOnClickListener {
            val username = binding.phone.text.toString()
            val password = binding.password.text.toString()
            if (username.isNullOrEmpty() || password.isNullOrEmpty()){
                ToastUtils.showLong("输入不能为空")
                return@setOnClickListener
            }
//            if (username.matches(Regex("[A-z0-9_]{2,8}"))){
//                ToastUtils.showLong("不是合法账号")
//            }
            vm.login(username,password)
        }
    }

    override fun initData() {
        vm.loginSuccess.observe(this){
            ToastUtils.showLong("登录成功")
            ARouter.getInstance().build("/app/MainActivity").navigation()
            if (it.roleid==2){

            }else {

            }
        }
    }

}